<!-- delete confirmation dialog box -->
<div id="delConfDialog" title="Confirm">
    <p>Anda yakin?</p>
</div>
<!-- message dialog box -->
<div id="msgDialog"><p></p></div>

<!-- edited by : alfin akhret
SSP datattables -->
<table id="records" class="handsetRecord">
    <thead>
    </thead>
    <tbody>
    </tbody>
</table>
<!--  -------------->

<script type="text/javascript">
var readUrl   = 'index.php/group_alias/get_group_alias_data',
updateUrl = '<?=base_url();?>index.php/group_alias',
delUrl    = '<?=base_url();?>index.php/group_alias/delete';
  

$( function() {
    
    readUsers();
    $( '#msgDialog' ).dialog({
        autoOpen: false,
        buttons: {
            'Ok': function() {
                $( this ).dialog( 'close' );
            }
        }
    });
    
    $( '#delConfDialog' ).dialog({
        autoOpen: false,
        buttons: {
            'No': function() {
                $( this ).dialog( 'close' );
            },
            'Yes': function() {
                //display ajax loader animation here...
                $( '#ajaxLoadAni' ).fadeIn( 'slow' );
                $( this ).dialog( 'close' );
                $.ajax({
                    url: delHref,
                    success: function( response ) {
                        //hide ajax loader animation here...
                        $( '#ajaxLoadAni' ).fadeOut( 'slow' );
                        
                        $( '#msgDialog > p' ).html( response );
                        $( '#msgDialog' ).dialog( 'option', 'title', 'Success' ).dialog( 'open' );
                        
                        $( 'a[href=' + delHref + ']' ).parents( 'tr' )
                        .fadeOut( 'slow', function() {
                            $( this ).remove();
                        });
                        
                    } //end success
                });
            } //end Yes
        } //end buttons
    }); //end dialog
    
    
    $( '#records' ).delegate( 'a.deleteBtn', 'click', function() {
        delHref = $( this ).attr( 'href' );
        $( '#delConfDialog' ).dialog( 'open' );
            return false;
    }); //end delete delegate
    // --- Create Record with Validation ---
}); //end document ready

function readUsers() {
    $('.handsetRecord').dataTable({
                "bJQueryUI": true, // aktifkan tampilan tabel JQueryUI
                "sAjaxSource": readUrl, //data source
                "sAjaxDataProp": "aaData", //variabel yg menampung data table
                "bServerSide": true, //serverside processing true
                "bProcessing": true, // tampilkan 'processing...' status saat data dipanggil
                // "sPaginationType": 'full_numbers',
                "bPaginate": true,
                "aoColumns":[ //tentukan kolom pd tabel yg akan menampung value dari server
                    {"mDataProp": "alias_id", "sTitle": "Alias ID", "bSearchable": false}, 
                    {"mDataProp": "alias_name", "sTitle": "User Group Alias Name"}, 
                    {"mDataProp": "user_group_name", "sTitle": "User Group Name"}
                ],
                "fnRowCallback": function(nRow, aaData, iDisplayIndex, iDisplayIndexFull) 
                {
                    $(nRow).find('td').eq(-1).after('<td><a href="'+updateUrl+'?update_alias_id='+aaData[0]+'">Update</a> | <a href="'+delUrl+'/'+aaData[0]+'" class="deleteBtn">Delete</a></td>');
                    return nRow;
                }
        });
        $('.handsetRecord thead tr').find('th').eq(-1).after('<th class="ui-state-default" width="200px">Action</th>');
}
</script>
